﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using KPIS.DBM;
using KPIS.GERP.SECURITY.MODEL;

namespace KPIS.GERP.SECURITY.DAL
{
    public class SysExecPosGroupDAL
    {
        DBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);

        public SysExecPosGroupDAL()
        {

        }
        public DataTable GetFull()
        {
            string strSQL;
            
            DataTable dtb = null;

            try
            {
                dbManager.Open();
                //dbManager.CreateParameters(3);

                //dbManager.AddParameters(0, "@ActiveRecord", SystemInfo._ActiveRecordStatus);
                //dbManager.AddParameters(1, "@Sequence", Sequence);
                //dbManager.AddParameters(2, "@System", System);

                strSQL = "SELECT exec_pos_group_seq, exec_pos_group_name"
                    + " FROM sys_exec_pos_group";

                dtb = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
            }
            catch
            {
                throw;
            }
            finally
            {
                dbManager.Dispose();
            }

            return dtb;
        }

        public DataTable GetDtlsFull(string exec_pos_group_seq)
        {
            string strSQL;

            DataTable dtb = null;

            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);

                dbManager.AddParameters(0, "@exec_pos_group_seq", exec_pos_group_seq);

                strSQL = "select gd.exec_pos_group_dtls_seq, gd.exec_pos_group_seq, gd.exec_pos_seq"
                    + ", exe.exec_pos_code, exe.exec_pos_name, exe.exec_pos_name_short"

                    + " from sys_exec_pos_group_dtls gd"
                    + " left join hrm_mp_exec_positions exe on gd.exec_pos_seq = exe.exec_pos_seq"
                    
                    + " where 0 = 0"
                    + (exec_pos_group_seq != null ? " and gd.exec_pos_group_seq = @exec_pos_group_seq" : "");

                dtb = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
            }
            catch
            {
                throw;
            }
            finally
            {
                dbManager.Dispose();
            }

            return dtb;
        }

        //public string SelectRecentInsertedRoleSeq()
        //{
        //    string strSQL;
        //    string strResult;

        //    try
        //    {
        //        dbManager.Open();

        //        strSQL = "select last_insert_id() as role_seq from roles";
        //        //strSQL = "select role_seq, role_name, system, remarks"
        //        //    + " from roles"
        //        //    + " where created_when = " + Misc.ValueForSQL(created_when);

        //        strResult = "";// Misc.StringValue(dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows[0]["role_seq"]);
        //    }
        //    catch
        //    {
        //        throw;
        //    }
        //    finally
        //    {
        //        dbManager.Dispose();
        //    }

        //    return strResult;
        //}

        //public void Insert(string RoleName, string System, string Remarks, int CreatedBy)
        //{
        //    try
        //    {
        //        string strSQL;
        //        dbManager.Open();
        //        dbManager.CreateParameters(6);

        //        dbManager.AddParameters(0, "@RoleName", RoleName);
        //        dbManager.AddParameters(1, "@System", System);
        //        dbManager.AddParameters(2, "@Remarks", Remarks);
        //        dbManager.AddParameters(3, "@RecordStatus", SystemInfo._ActiveRecordStatus);
        //        dbManager.AddParameters(4, "@CreatedBy", CreatedBy);
        //        dbManager.AddParameters(5, "@CreatedWhen", DateTime.Now);

        //        strSQL = "INSERT INTO SYS_SC_ROLES"
        //            + "(ROLE_NAME, SYSTEM, REMARKS, RECORD_STATUS, CREATED_BY, CREATED_WHEN)"
        //            + " VALUES (@RoleName, @System, @Remarks, @RecordStatus, @CreatedBy, @CreatedWhen)";
         
        //        dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
        //    }
        //    catch
        //    {
        //        throw;
        //    }
        //    finally
        //    {
        //        dbManager.Dispose();
        //    }
        //}

        //public void Update(int Sequence, string RoleName, string System, string Remarks, int UpdatedBy)
        //{            
        //    try
        //    {
        //        string strSQL;

        //        dbManager.Open();
        //        dbManager.CreateParameters(6);

        //        dbManager.AddParameters(0, "@Sequence", Sequence);
        //        dbManager.AddParameters(1, "@RoleName", RoleName);
        //        dbManager.AddParameters(2, "@System", System);
        //        dbManager.AddParameters(3, "@Remarks", Remarks);
        //        dbManager.AddParameters(4, "@UpdatedBy", UpdatedBy);
        //        dbManager.AddParameters(5, "@UpdatedWhen", DateTime.Now);

        //        strSQL = "UPDATE SYS_SC_ROLES"
        //            + " SET ROLE_NAME = @RoleName"
        //                + ", SYSTEM = @System"
        //                + ", REMARKS = @Remarks"
        //                + ", UPDATED_BY = @UpdatedBy"
        //                + ", UPDATED_WHEN = @UpdatedWhen"
        //            + " WHERE ROLE_SEQ = @Sequence";

        //        dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
        //    }
        //    catch
        //    {
        //        throw;
        //    }
        //    finally
        //    {
        //        dbManager.Dispose();
        //    }
        //}

        //public void Delete(int Sequence, int UpdatedBy)
        //{
        //    try
        //    {
        //        string strSQL;

        //        dbManager.Open();
        //        dbManager.CreateParameters(4);

        //        dbManager.AddParameters(0, "@Sequence", Sequence);
        //        dbManager.AddParameters(1, "@DeleteRecord", SystemInfo._DeleteRecordStatus);
        //        dbManager.AddParameters(2, "@UpdatedBy", UpdatedBy);
        //        dbManager.AddParameters(3, "@UpdatedWhen", DateTime.Now);

        //        strSQL = "UPDATE SYS_SC_ROLES"
        //            + " SET RECORD_STATUS = @DeleteRecord"
        //                + ", UPDATED_BY = @UpdatedBy"
        //                + ", UPDATED_WHEN = @UpdatedWhen"
        //            + " WHERE ROLE_SEQ = @Sequence";
        //        dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
        //    }
        //    catch
        //    {
        //        throw;
        //    }
        //    finally
        //    {
        //        dbManager.Dispose();
        //    }
        //}
    }
}
